<template>
  <div class='searchHistory'>
    <van-cell
     title="历史记录"
    >
      <div v-if="isDeleteShow">
        <span @click="$emit('deleteAllSearchHistories', [])">
          全部删除
        </span>
          &nbsp;&nbsp;
        <span @click="isDeleteShow = false">
          完成
        </span>
      </div>
      <van-icon
        v-else
        @click="isDeleteShow = true"
        name="delete"
      />
    </van-cell>
    <van-cell
      v-for="(history, index) in searchHistories"
      :title="history"
      :key="index"
      @click="$emit('search', history)"
    >
      <van-icon
        v-if="isDeleteShow"
        name="close"
        @click.stop
        @click="deleteHistory(index)"
      />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'searchHistory',
  components: {},
  props: {
    searchHistories: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      isDeleteShow: false
    }
  },
  methods: {
    deleteHistory (index) {
      this.searchHistories.splice(index, 1)
    }
  }
}
</script>
<style lang='less' scoped></style>
